package com.jt.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.jt.mapper.ItemListMapper;
import com.jt.pojo.ItemList;
import com.jt.vo.ItemVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;

import java.util.List;

@Service
public class ItemListServiceimpl implements ItemListService{

    @Autowired
    private ItemListMapper itemListMapper;

    @Override
    public List<ItemList> selectPageList() {
        List<ItemList> list = itemListMapper.selectList(null);
        return list;
    }

    @Override
    public List<ItemList> selectrecommendList() {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("Hot_id", 1);
        List<ItemList> list = itemListMapper.selectList(queryWrapper);
        return list;
    }

    @Override
    public List<ItemList> selectHotList() {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("Hot_id", 2 );
        List<ItemList> Hotlist = itemListMapper.selectList(queryWrapper);
        return Hotlist;
    }

    @Override
    @Transactional
    public void saveItem(ItemVO itemVO) {
        ItemList item=itemVO.getItemList();
        String details=itemVO.getDetails();
        item.setDetails(details);
        itemListMapper.insert(item);
    }

    @Override
    public List<ItemList> toQuery(String query) {
        boolean flag= StringUtils.hasLength(query);
        List<ItemList> list=itemListMapper.selectList(new QueryWrapper<ItemList>()
                .like(flag,"name", query)
        );
        return list;
    }
}
